<?php  if ( ! defined('IN_DiliCMS')) exit('No direct script access allowed');
	class Search_m extends CI_Model{
		function __construct()
		{
			parent::__construct();
		}
			
		function get_des_tags()		//分区标签分类数组
		{
			$sql="select classid,classname,parentid from  dili_u_c_class_tags";
			$contentModels=$this->db->query($sql)->result();
			//$lines_title[$item->id]=$item->trav_title;
			$des_tags="";
			foreach($contentModels as $class){
				$des_tags['classname'][$class->classid]=$class->classname;
		//		$des_tags[$class->classid]['parentid']=$class->parentid;
				$des_tags['parentid'][$class->parentid][$class->classid]=$class->classname;
			}
	//		print_r($des_tags['classname']);
			return $des_tags;
		}
		function get_tags_pid($cid=0)
		{
			if($cid){
				$sql="select classid from  dili_u_c_class_tags where rela_classid=".$cid;	
				$tags_pid=$this->db->query($sql)->result();
				return $tags_pid[0]->classid;
			}else{
				return 0;
			}
		
		}
		function get_search_list($cateid=0,$tagid=0,$type=0,$begin_record=0,$per_page=10){
			if((int)$cateid || (int)$tagid){
				$datawhere="";
				if((int)$cateid){	//判断参数是否有效
					$datawhere=" and  (INSTR(line_class,',$cateid-') or INSTR(line_class,'-$cateid,')) and length(line_class)>2";
				}
				if((int)$tagid){	//判断参数是否有效
					$datawhere.=" and  (INSTR(line_tags,'$tagid-') or INSTR(line_tags,'-$tagid')) and   length(line_tags)>2";
				}	
				if($type==0){
					if(!$begin_record){$begin_record=0;}
					$sear_fields="id,update_time,trav_title,price_per,departure_date,transparency,tuijian,line_tags,TravelTime,line_info,name,folder,type";
					$sql="select ".$sear_fields." from  dili_u_m_trav_lines as l left join dili_attachments as a on l.id=a.content where 1=1 $datawhere group by id limit $begin_record,$per_page";
						
				}else{
					$sear_fields=" count(id) as icount";
					$sql="select ".$sear_fields." from  dili_u_m_trav_lines where 1=1 $datawhere ";
				}							
				$search_list=$this->db->query($sql)->result();
			//	print_r($sql);
			//	print_r($search_list);
			//	if(count($search_list)){
					return $search_list;
			//	}else{
			//		return false;
			//	}
				
				
			}
			
			
		}
		
		
		
		
	}